package com.com.xinke.edu.petmall;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.MenuItem;

import androidx.activity.EdgeToEdge;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import androidx.fragment.app.Fragment;

import com.com.xinke.edu.petmall.databinding.ActivityMainBinding;
import com.com.xinke.edu.petmall.fragment.home.HomeFragment;
import com.com.xinke.edu.petmall.fragment.mine.WoFragment;
import com.google.android.material.navigation.NavigationBarView;

public class MainActivity extends AppCompatActivity {
    ActivityMainBinding binding;
    HomeFragment homeFragment=new HomeFragment();
    WoFragment woFragment=new WoFragment();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
//        EdgeToEdge.enable(this);
        binding = ActivityMainBinding.inflate(LayoutInflater.from(this));
        setContentView(binding.getRoot());
        getSupportFragmentManager().beginTransaction().replace(R.id.conner,homeFragment).commit();

        binding.navigation.setOnItemSelectedListener(new NavigationBarView.OnItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                Fragment fragment=null;
                if(item.getItemId()==R.id.home){
                    fragment=homeFragment;
                }else if(item.getItemId()==R.id.mine){
                    fragment=woFragment;
                }
                getSupportFragmentManager().beginTransaction().replace(R.id.conner,fragment).commit();
                return true; //处理了这次点击事件
            }
        });
    }
}